package hk.ust.android_competition.activities;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.Toast;

import hk.ust.android_competition.data_reload_tools.TextReader;
import hk.ust.android_competition.e_pet.R;


public class OpeningActivity extends LandscapeFullScreenActivity {
    private ImageView image;
    int[] imageIds = {R.drawable.opening, R.drawable.opening2};
    int index = 0;
    String path;
    long delay = 2000;
    Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_opening);
        image = (ImageView) findViewById(R.id.open1);
        path = getFilesDir() + "UserData.txt";
        intent = new Intent();
        intent.putExtra("data path", path);
        TextReader tr = new TextReader(path);
        if (tr.getData().equals("Not exist")) {
            intent.setClass(this, CharacterSelectActivity.class);
        } else {
            intent.putExtra("status", "user exist");
            intent.setClass(this, MainActivity.class);
        }
        image.setImageResource(imageIds[index++]);
        Runnable swapImage = new Runnable() {
            @Override
            public void run() {
                if (index == imageIds.length) {
                    startActivity(intent);
                    finish();
                } else {
                    image.setImageResource(imageIds[index++]);
                }
            }
        };
        for (int i = 0; i <= imageIds.length; i++) {
            image.postDelayed(swapImage, (i + 1) * delay);
        }

    }
}
